package com.cjm.algorithm.leetcode;

import java.util.*;

public class SimplifyPath71 {
    public static String simplifyPath(String path) {
        Stack<String> stack = new Stack<>();
        String[] split = path.split("/");
        for (String s : split) {
            if (s.equals("") || s.equals(".")) continue;
            if (s.equals("..")) {
                if (!stack.isEmpty()) stack.pop();
            } else {
                stack.push(s);
            }
        }
        StringBuilder res = new StringBuilder();
        for (String s : stack) {
            res.append("/");
            res.append(s);
        }
        if (res.length() == 0) return "/";
        return res.toString();
    }

    private static boolean isleter(char temp) {
        return (97 <= temp && temp <= 123) || temp == '_';
    }

    public static void main(String[] args) {

    }
}
